<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <body>
    <input type="text" name="username" />
    <input type="text" name="username" />
  </body>
  
  <!-- 如果使用的是querySelector, 那么将获取到的是第一个 -->
  <script>
    document
      // .querySelector(`[name="username"]`)
      .querySelector('input')
      .addEventListener("keyup", function() {
        let res = this.value.match(/^[a-z]{3,6}$/i);
        console.log(res ? res[0]:res);
        console.log(res ? "正确" : "失败");
      });
      
  </script>
</body>
</html>